package org.dromara.oce.domain.req;

import lombok.Data;
import org.dromara.oce.utils.DateTimeUtil;

import java.math.BigDecimal;

@Data
public class OrderAmountHoursDTO {


    //推广链接id")
    private Long referralLinkId;

    //当日日期时间戳")
    private Long thatdayTimestamp;

    //当日某时时间戳yyyy-mm-dd HH")
    private Long thatdayHoursTimestamp;
    //    当日某时时间")
    private String thatdayHoursDate;

    //当日总收入")
    private BigDecimal thatdayTotalAmount = BigDecimal.ZERO;
    //当日分成金额")
    private BigDecimal thatdayDividendAmount = BigDecimal.ZERO;
    //当日利润金额=当日分成金额-当日消耗")
    private BigDecimal thatdayProfitAmount = BigDecimal.ZERO;
    //当日总支付笔数")
    private Integer thatdayPaidTotalNum = 0;
    //当日付款人数")
    private Integer thatdayPaidUseNum = 0;

    //当日注册用户的总收入")
    private BigDecimal thatdayRegisterTotalAmount = BigDecimal.ZERO;
    //    当日注册用户的分成金额")
    private BigDecimal thatdayRegisterDividendAmount = BigDecimal.ZERO;


    //商务当日分成金额
    private BigDecimal thatdayDividendAmountSw = BigDecimal.ZERO;
    //商务当日注册用户的分成金额
    private BigDecimal thatdayRegisterDividendAmountSw = BigDecimal.ZERO;
    //商务当日IAA分成金额
    private BigDecimal iaaDividendAmountSw = BigDecimal.ZERO;
    //商务当日注册用户的IAA分成金额
    private BigDecimal iaaRegisterDividendAmountSw = BigDecimal.ZERO;
    //商务当日利润金额=商务当日分成金额-当日消耗/1.015
    private BigDecimal thatdayProfitAmountSw = BigDecimal.ZERO;
    //商务当日新增利润=商务当日注册用户的分成金额-当日消耗/1.015
    private BigDecimal thatdayRegisterProfitAmountSw = BigDecimal.ZERO;


    //当前时段的总金额")
    private BigDecimal amountHoursCurrent = BigDecimal.ZERO;
    //当前时段+1的总金额")
    private BigDecimal amountHoursOne = BigDecimal.ZERO;
    //当前时段+2的总金额")
    private BigDecimal amountHoursTwo = BigDecimal.ZERO;
    //当前时段+3的总金额")
    private BigDecimal amountHoursThree = BigDecimal.ZERO;
    //当前时段+4的总金额")
    private BigDecimal amountHoursFour = BigDecimal.ZERO;
    //当前时段+n的总金额")
    private BigDecimal amountHoursFive = BigDecimal.ZERO;

    //当前时段的分成金额")
    private BigDecimal dividendAmountHoursCurrent = BigDecimal.ZERO;
    //当前时段+1的分成金额")
    private BigDecimal dividendAmountHoursOne = BigDecimal.ZERO;
    //当前时段+2的分成金额")
    private BigDecimal dividendAmountHoursTwo = BigDecimal.ZERO;
    //当前时段+3的分成金额")
    private BigDecimal dividendAmountHoursThree = BigDecimal.ZERO;
    //当前时段+4的分成金额")
    private BigDecimal dividendAmountHoursFour = BigDecimal.ZERO;
    //当前时段+n的分成金额")
    private BigDecimal dividendAmountHoursFive = BigDecimal.ZERO;


    //番茄订单时才使用，点众分成金额是算好的
    //    ios当日总收入")
    private BigDecimal iosThatdayTotalAmount = BigDecimal.ZERO;
    //    ios当日注册用户的总收入")
    private BigDecimal iosThatdayRegisterTotalAmount = BigDecimal.ZERO;
    //    当前时段的总金额")
    private BigDecimal iosAmountHoursCurrent = BigDecimal.ZERO;
    //    当前时段+1的总金额")
    private BigDecimal iosAmountHoursOne = BigDecimal.ZERO;
    //    当前时段+2的总金额")
    private BigDecimal iosAmountHoursTwo = BigDecimal.ZERO;
    //    当前时段+3的总金额")
    private BigDecimal iosAmountHoursThree = BigDecimal.ZERO;
    //    当前时段+4的总金额")
    private BigDecimal iosAmountHoursFour = BigDecimal.ZERO;
    //    当前时段+n的总金额")
    private BigDecimal iosAmountHoursFive = BigDecimal.ZERO;


    /**
     * 计算交易属于哪个T时段
     *
     * @param registerTimestamp
     * @param payTimestamp
     * @param dividendAmount
     */
    public void hoursBlockAddAmount(long registerTimestamp, long payTimestamp, BigDecimal dividendAmount) {
        try {
            registerTimestamp = DateTimeUtil.getHoursTimestamp(registerTimestamp);
            payTimestamp = DateTimeUtil.getHoursTimestamp(payTimestamp);

            int registerHours = DateTimeUtil.getHours(registerTimestamp);
            int payHours = DateTimeUtil.getHours(payTimestamp);

            long hoursNum = (payTimestamp - registerTimestamp) / 3600;
            if (hoursNum == 0 && registerHours == payHours) {
                this.dividendAmountHoursCurrent = this.dividendAmountHoursCurrent.add(dividendAmount);
            } else if (hoursNum == 0) {
                this.dividendAmountHoursOne = this.dividendAmountHoursCurrent.add(dividendAmount);
            } else if (hoursNum == 1) {
                this.dividendAmountHoursOne = this.dividendAmountHoursOne.add(dividendAmount);
            } else if (hoursNum == 2) {
                this.dividendAmountHoursTwo = this.dividendAmountHoursTwo.add(dividendAmount);
            } else if (hoursNum == 3) {
                this.dividendAmountHoursThree = this.dividendAmountHoursThree.add(dividendAmount);
            } else if (hoursNum == 4) {
                this.dividendAmountHoursFour = this.dividendAmountHoursFour.add(dividendAmount);
            } else {
                this.dividendAmountHoursFive = this.dividendAmountHoursFive.add(dividendAmount);
            }
        } catch (Exception e) {
            System.out.println("计算时段分成金额异常");
        }
    }

}
